package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.YaoYueEditItem
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import org.json.JSONObject
import kotlin.reflect.KFunction0
import kotlin.reflect.KFunction1

class ReceptionRepository {
    fun update(id: String, arrivetime: String, arrpnum: Int, rcvuid: Int, kFunction0: KFunction0<Unit>) {
        ApiClient.getInstance().update(id, arrivetime, arrpnum, rcvuid)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<JSONObject>>() {
                    override fun onSuccess(t: BaseResp<JSONObject>) {
                        kFunction0()
                    }

                    override fun onError(ex: ApiException) {

                    }


                })

    }

    /**
     * 获取信息
     */
    fun getInviteEdit(id: String, kFunction1: KFunction1<@ParameterName(name = "item") YaoYueEditItem, Unit>) {
        ApiClient.getInstance().getInviteEdit(id)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<YaoYueEditItem>>() {
                    override fun onSuccess(t: BaseResp<YaoYueEditItem>) {
                        t.data?.apply(kFunction1)
                    }

                    override fun onError(ex: ApiException) {

                    }


                })

    }

}